var express = require('express');
var router = express.Router();


router.get('/home', function (req, res) {

    return res.redirect(303, '/views/dbHome.html');
});
router.get('/', function (req, res) {

    var tname = req.query.tname  ||'user';
    let db = new HandleDB();
    db.connectDataBase().then((result) => {
        var sqlStr = `select * from ${tname}`;
        console.log(sqlStr);
        db.sql(sqlStr, [], 'all').then((items) => {
            res.json({
                code: 0,
                dat: items
            })
        }).catch((err) => {
            console.log(err);
        });

    }).catch((err) => {
        console.error(err);
    });


    
});



module.exports = router;
